package networkSimulation.simulation.social.statistic

import networkSimulation.statistic.{VisualStatistics, Statistic}
import networkSimulation.framework.Graph
import networkSimulation.simulation.social.framework.{GayCommunity, FootBall, School, Friendship, Person}

/**
 * Created by IntelliJ IDEA.
 * User: Jorick
 * Date: 18-nov-2011
 * Time: 13:26:42
 * To change this template use File | Settings | File Templates.
 */

class PercentageIncreased  [N<%Person,E<%Friendship[N]] extends Statistic[N,E]{
  private var school = 0
  private var football = 0
  private var gayCommunity = 0
  private var schoolAmounts =List[Int]()
  private var footballAmounts =List[Int]()
  private var gayCommunityAmounts =List[Int]()

  @Override
  override def generateStatistic(vis:VisualStatistics,path : String){
    var list = List[Int]()
    var strings = List[String]()
    strings::= "School"
    strings::= "Football"
    strings::= "GayCommunity"
    val schoolTemp = schoolAmounts.head - schoolAmounts.last
    if(schoolAmounts.last==0){
      list::= 0
    }else{
       list::=(schoolTemp*100/schoolAmounts.last)
    }
    val footballTemp = footballAmounts.head - footballAmounts.last
    if(footballAmounts.last==0){
      list::= 0
    }else{
       list::=(footballTemp*100/footballAmounts.last)
    }
    val gayTemp = gayCommunityAmounts.head - gayCommunityAmounts.last
    if(gayCommunityAmounts.last==0){
      list::= 0
    }else{
       list::=(gayTemp*100/gayCommunityAmounts.last)
    }
    vis.createBarChart("Percentage Friends Increased","Amount",list,strings,"Friendships",path)
  }

  @Override
  override def updateStatistics(graph: Graph[N, E],k:String){
    school = 0
    football = 0
    gayCommunity = 0
    for(edge: E <- graph.edges){
      if(edge.isInstanceOf[School[E]]){
        school+=1
      }
      if(edge.isInstanceOf[FootBall[E]]){
        football+=1
      }
      if(edge.isInstanceOf[GayCommunity[E]]){
        gayCommunity+=1
      }
    }
    key = k
  }

  @Override
  override def loadData(data : xml.NodeSeq){
    schoolAmounts ::= (data \\ "School").text.toInt
    footballAmounts ::= (data \\ "Football").text.toInt
    gayCommunityAmounts ::= (data \\ "GayCommunity").text.toInt
  }

  @Override
  override def toXml(): xml.NodeSeq  = {
    <Stat key={key}>
      <School>{ school }</School>
      <Football>{ football }</Football>
      <GayCommunity>{ gayCommunity }</GayCommunity>
    </Stat>
  }
}